#ifndef CURRENTCONTEXT_H_INCLUDED
#define CURRENTCONTEXT_H_INCLUDED

#include <iostream>
#include <sys/types.h>
#include <SDL/SDL.h>
#include "Debug.h"
#include "Mutex_Wrapper.h"

#define ACTIVE_SPRITE   1

using namespace std;

class CurrentContext {
    int m_activeLayerIndex;
    uint m_activeSpriteInstanceIndex;
    uint m_activeSpriteInstanceImageIndex;
    uint m_activeSpriteInstanceSpriteIndex;
    SDL_Rect m_activeSprtieRect;
    uint m_available;
    Mutex_Wrapper m_mutex;

protected:
    static CurrentContext* instance;

public:
    void invalidateActiveSpriteInfo();
    uint getCurrentLayerIndex();
    void setCurrentLayerIndex(uint index);
    bool getActiveSpriteInfo(uint &activeSpriteInstanceIndex,
        uint &activeSpriteInstanceImageIndex, uint &activeSpriteInstanceSpriteIndex,
        SDL_Rect &activeSprtieRect) const;
    bool setActiveSpriteInfo(uint &activeSpriteInstanceIndex,
        uint &activeSpriteInstanceImageIndex, uint &activeSpriteInstanceSpriteIndex,
        SDL_Rect &activeSprtieRect);
    static CurrentContext* get_instance();
    static void destroy();
    ~CurrentContext();
    void lock();
    void unlock();


protected:
    CurrentContext();
};

inline void CurrentContext::invalidateActiveSpriteInfo()
{
    m_available = 0;
}

inline void CurrentContext::lock()
{
    m_mutex.lock();
}

inline void CurrentContext::unlock()
{
    m_mutex.unlock();
}

#endif // CURRENTCONTEXT_H_INCLUDED
